<?php
use common\components\helpers\Fun;
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use common\components\extenders\MenuManage;
use doumiaoduo\layer\LayerIframeWidget;
use doumiaoduo\layer\LayerAsset;
LayerAsset::register($this);

LayerIframeWidget::widget(['button'=>"['添加','取消']"]);
?>
<div class="yx-cnt-box yx-radius2">
    <div class="yx-praise-box">
        <div class="yx-search-class">
            <a href="<?=Fun::url(['customer/details','id'=>\Yii::$app->request->get('id')])?>">
                <button type="button" class="btn yx-back-list yx-radius5 yx-width110">返回上级</button>
            </a>
            <div class="yx-bgf7 yx-height108">
                <h4 class="yx-teacher-praise yx-floatl ">会员姓名：<?= $customer->name ?></h4>
                <?php if(\Yii::$app->controller->action->id == 'order'):?>
                    <h4 class="yx-teacher-praise yx-pl20 yx-floatl">当前可用奖学金：<span class="yx-color2cb4f3 yx-font16"><?= isset($account->scholarship_available)?$account->scholarship_available:0 ?></span>元</h4>
                <?php endif;?>
                <h4 class="yx-teacher-praise yx-pl20 yx-floatl">当前可用余额：<span class="yx-color2cb4f3 yx-font16"><?= isset($account->cash)?$account->cash:0 ?></span>元</h4>
                <div class="yx-clear"></div>
            </div>
            <div class="yx-class-box yx-pt18 yx-pb6">
                <div class="docs-main">
                    <table id="tablep" class="tablesaw table yx-table1 yx-table3 yx-table5 table-striped with-check"  data-url="<?=Fun::url(['customer/add'])?>" >
                        <thead>
                        <tr class="yx-bgd2f6ec">
                            <th>类别名称</th>
                            <th>商品名称</th>
                            <th>商品类型</th>
                            <th>库存总量</th>
                            <th>单节课次价格</th>
                            <th>教师名称</th>
                            <th>教室</th>
                            <th>上课时间</th>
                            <th>满额人数</th>
                            <th class="yx-br">开班人数</th>
                        </tr>
                        </thead>
                        <tr>
                            <td><?=isset($goods->cate->name)?$goods->cate->name:''?></td>
                            <td><?=$goods->name?></td>
                            <td><?php
                                switch ($goods->category_id){
                                    case 1:
                                        echo '益智';
                                        break;
                                    case 2:
                                        echo '音乐';
                                        break;
                                    default:
                                        echo '形体';

                                }
                                ?></td>
                            <td><?=$goods->store?></td>
                            <td><?=$goods->price?></td>
                            <td><?php
                                $teacher = \zhtfrontend\models\datas\GoodsTeacher::find()->select('teacher_name')->where(['goods_id'=>$goods->id])->column();
                                $str = '';
                                if(!empty($teacher)){
                                    $str = implode(',',$teacher);
                                }
                                echo $str;
                                ?></td>
                            <td><?php
                                 $classroom = \zhtfrontend\models\datas\GoodsAttr::find()->where(['goods_id'=>$goods->id,'obj_type'=>'classroom_name'])->one();
                                 echo isset($classroom->value)?$classroom->value:''
                                ?></td>
                            <td><?php
                                $goodsTime = \zhtfrontend\models\datas\GoodsClassTime::find()->where(['goods_id'=>$goods->id])->all();
                                $str = '';
                                if($goodsTime != null){
                                    foreach ($goodsTime as $time){
                                        $str .= \common\components\helpers\Util::getWeek($time->class_day).$time->start_time.'-'.$time->end_time;
                                    }
                                }
                                echo $str;
                                ?></td>
                            <td><?php
                                $classroom = \zhtfrontend\models\datas\GoodsAttr::find()->where(['goods_id'=>$goods->id,'obj_type'=>'max_number'])->one();
                                echo isset($classroom->value)?$classroom->value:''
                                ?></td>
                            <td><?php
                                $classroom = \zhtfrontend\models\datas\GoodsAttr::find()->where(['goods_id'=>$goods->id,'obj_type'=>'opening_number'])->one();
                                echo isset($classroom->value)?$classroom->value:''
                                ?></td>
                        </tr>

                    </table>
                    <div class="price_list">
                        <div style="float: left;margin-bottom:10px;">
                            <span class="zx-label" style="width: auto !important">选择价格套餐</span>
                            <select name="goods_price_id" class="form-control"  data-act="orders-goods_price_id" style='width:510px'>
                                <option value="">请选择...</option>
                                <?php foreach ($goodsPrice as $price) { ?>
                                    <option value="<?=$price['id']?>" data-price="<?=$price['market_price']?>"><?=$price['price_name']?>-价格<?=$price['market_price']?>-课次<?=$price['lesson']?></option>
                                <?php }?>
                            </select>
                            <?=Html::hiddenInput('goods_hidden',0,['id'=>'selectgoodsprice'])?>
                        </div>

                       <div class="yx-clear"></div>
                    </div>

                </div>
            </div>
        </div>

        <div class="yx-class-box yx-bt" style="padding-top: 20px">
            <?php $form = ActiveForm::begin(['enableAjaxValidation' => true, 'enableClientValidation' => false,'options'=>['class'=>'form-validate form-horizontal']]); ?>
            <div class="control-group" style="display: none;margin-bottom:0;">
                <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['total_amount']; ?></label>
                <div class="controls">
                    <?= $form->field($model, 'total_amount', ['template' => '{input}{error}'])->hiddenInput(); ?>
                </div>
            </div>

            <div class="control-group" style="display: none;margin-bottom:0;">
                <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['item_num']; ?></label>
                <div class="controls">
                    <?= $form->field($model, 'item_num', ['template' => '{input}{error}'])->hiddenInput(); ?>
                </div>
            </div>
            <div class="control-group" style="margin-bottom:0;">
                <label class="control-label control-label1 yx-mr25" for="inputTime">合计金额</label>
                <div class="controls">
                    <span class="yx-font18 yx-color4f4f4f" style="line-height:35px;" id="amount">0.00</span>
                </div>
            </div>
             <div class="control-group" style="margin-bottom:0;">
                    <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['final_amount']; ?></label>
                    <div class="controls">
                        <?= $form->field($model, 'final_amount', ['template' => '{input}{error}{hint}'])->textInput([ 'readonly' => 'true', 'value' => 0, 'class' => 'input-text']) ?>
                    </div>
                </div>

            <div class="control-group" style="margin-bottom:0;">
                <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['goods_id']; ?></label>
                <div class="controls">
                    <?= $form->field($model, 'goods_id', ['template' => '{input}{error}'])->textInput([ 'class' => 'input-text','readonly'=>true]); ?>
                </div>
            </div>
            <div class="control-group" style="display: none;margin-bottom:0; ">
                <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['goods_price_id']; ?></label>
                <div class="controls">
                    <?= $form->field($model, 'goods_price_id', ['template' => '{input}{error}'])->textInput(['style' => 'width:100px', 'class' => 'input-text','readonly'=>true]); ?>
                </div>
            </div>
            <div class="control-group" style="margin-bottom:0;">
                <label class="control-label control-label1 yx-mr25" for="inputTime"><?= $model->attributeLabels()['remarks']; ?></label>
                <div class="controls">
                    <?= $form->field($model, 'remarks', ['template' => '{input}{error}{hint}'])->textarea(['rows' => 2,'class' => 'textarea_editor yx-width510 yx-height56']) ?>
                </div>
            </div>
                <div class="yx-button-group">
                    <button type="button" id="dosubmit" class="btn yx-save yx-radius50">提交</button>
                    <a href="<?=Fun::url(['customer/details','id'=>$customer->id])?>" class="btn yx-close1 yx-radius50 yx-ml4" style="display: inline-block">返回</a>
                </div>
            <?php ActiveForm::end(); ?>
        </div>

    </div>
</div>
<?php
$js=<<<JS
 $(document).on('click','#dosubmit',function() {
      var goods_price_id = $('select[name="goods_price_id"]').val();
      if(goods_price_id.length == 0){
          layer.msg("请选择先添加商品并选择价格！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 2000});
          return false;
      }else{
          $('#goods_price_id').val('');
          $('#w0').submit();
      }
 });
 
 $(document).on('change','select',function() {
     var id = $(this).val();
     var act = $(this).data('act'); 
     //if(act === 'orders-goods_price_id'){
     var price = parseFloat($(this).find('option:selected').data('price'));
     $('#orders-final_amount').val(price);
     $('#orders-total_amount').val(price);
     $('#amount').html(price);
    // }
     $('#'+act).val(id);
     
     
 })
JS;
\Yii::$app->view->registerJs($js);
?>